package com.flyco.dialog.widget.base;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import com.flyco.animation.BaseAnimatorSet;
import com.flyco.animation.BaseAnimatorSet.AnimatorListener;
import com.flyco.dialog.utils.StatusBarUtils;
import com.nineoldandroids.animation.Animator;

public abstract class BaseDialog extends Dialog
{
  protected String TAG;
  protected boolean cancel;
  protected Context context;
  private BaseAnimatorSet dismissAnim;
  protected DisplayMetrics dm;
  protected float heightScale;
  private boolean isDismissAnim;
  private boolean isShowAnim;
  protected LinearLayout ll_control_height;
  protected LinearLayout ll_top;
  protected float maxHeight;
  private BaseAnimatorSet showAnim;
  protected float widthScale = 1.0F;

  public BaseDialog(Context paramContext)
  {
    super(paramContext);
    setDialogTheme();
    this.context = paramContext;
    this.TAG = getClass().getSimpleName();
    Log.d(this.TAG, "constructor");
  }

  private void setDialogTheme()
  {
    requestWindowFeature(1);
    getWindow().setBackgroundDrawable(new ColorDrawable(0));
    getWindow().addFlags(2);
  }

  public BaseDialog dimEnabled(boolean paramBoolean)
  {
    if (paramBoolean)
    {
      getWindow().addFlags(2);
      return this;
    }
    getWindow().clearFlags(2);
    return this;
  }

  public void dismiss()
  {
    Log.d(this.TAG, "dismiss");
    if (this.dismissAnim != null)
    {
      this.dismissAnim.listener(new BaseAnimatorSet.AnimatorListener()
      {
        public void onAnimationCancel(Animator paramAnonymousAnimator)
        {
          BaseDialog.access$102(BaseDialog.this, false);
          BaseDialog.this.superDismiss();
        }

        public void onAnimationEnd(Animator paramAnonymousAnimator)
        {
          BaseDialog.access$102(BaseDialog.this, false);
          BaseDialog.this.superDismiss();
        }

        public void onAnimationRepeat(Animator paramAnonymousAnimator)
        {
        }

        public void onAnimationStart(Animator paramAnonymousAnimator)
        {
          BaseDialog.access$102(BaseDialog.this, true);
        }
      }).playOn(this.ll_control_height);
      return;
    }
    superDismiss();
  }

  public BaseDialog dismissAnim(BaseAnimatorSet paramBaseAnimatorSet)
  {
    this.dismissAnim = paramBaseAnimatorSet;
    return this;
  }

  public boolean dispatchTouchEvent(MotionEvent paramMotionEvent)
  {
    if ((this.isDismissAnim) || (this.isShowAnim))
      return true;
    return super.dispatchTouchEvent(paramMotionEvent);
  }

  protected int dp2px(float paramFloat)
  {
    return (int)(0.5F + paramFloat * this.context.getResources().getDisplayMetrics().density);
  }

  public BaseDialog heightScale(float paramFloat)
  {
    this.heightScale = paramFloat;
    return this;
  }

  public void onAttachedToWindow()
  {
    super.onAttachedToWindow();
    Log.d(this.TAG, "onAttachedToWindow");
    setUiBeforShow();
    int i;
    int j;
    if (this.widthScale == 0.0F)
    {
      i = -2;
      if (this.heightScale != 0.0F)
        break label109;
      j = -2;
    }
    while (true)
    {
      this.ll_control_height.setLayoutParams(new LinearLayout.LayoutParams(i, j));
      if (this.showAnim == null)
        break label139;
      this.showAnim.listener(new BaseAnimatorSet.AnimatorListener()
      {
        public void onAnimationCancel(Animator paramAnonymousAnimator)
        {
          BaseDialog.access$002(BaseDialog.this, false);
        }

        public void onAnimationEnd(Animator paramAnonymousAnimator)
        {
          BaseDialog.access$002(BaseDialog.this, false);
        }

        public void onAnimationRepeat(Animator paramAnonymousAnimator)
        {
        }

        public void onAnimationStart(Animator paramAnonymousAnimator)
        {
          BaseDialog.access$002(BaseDialog.this, true);
        }
      }).playOn(this.ll_control_height);
      return;
      i = (int)(this.dm.widthPixels * this.widthScale);
      break;
      label109: if (this.heightScale == 1.0F)
        j = -1;
      else
        j = (int)(this.maxHeight * this.heightScale);
    }
    label139: BaseAnimatorSet.reset(this.ll_control_height);
  }

  public void onBackPressed()
  {
    if ((this.isDismissAnim) || (this.isShowAnim))
      return;
    super.onBackPressed();
  }

  protected void onCreate(Bundle paramBundle)
  {
    Log.d(this.TAG, "onCreate");
    this.dm = this.context.getResources().getDisplayMetrics();
    this.ll_top = new LinearLayout(this.context);
    this.ll_top.setGravity(17);
    this.ll_control_height = new LinearLayout(this.context);
    this.ll_control_height.setOrientation(1);
    this.ll_control_height.addView(onCreateView());
    this.ll_top.addView(this.ll_control_height);
    this.maxHeight = (this.dm.heightPixels - StatusBarUtils.getHeight(this.context));
    setContentView(this.ll_top, new ViewGroup.LayoutParams(this.dm.widthPixels, (int)this.maxHeight));
    setCanceledOnTouchOutside(true);
    this.ll_top.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        if (BaseDialog.this.cancel)
          BaseDialog.this.dismiss();
      }
    });
  }

  public abstract View onCreateView();

  public void onDetachedFromWindow()
  {
    super.onDetachedFromWindow();
    Log.d(this.TAG, "onDetachedFromWindow");
  }

  protected void onStart()
  {
    super.onStart();
    Log.d(this.TAG, "onStart");
  }

  protected void onStop()
  {
    super.onStop();
    Log.d(this.TAG, "onStop");
  }

  public void setCanceledOnTouchOutside(boolean paramBoolean)
  {
    this.cancel = paramBoolean;
    super.setCanceledOnTouchOutside(paramBoolean);
  }

  public abstract boolean setUiBeforShow();

  public void show()
  {
    Log.d(this.TAG, "show");
    super.show();
  }

  public void show(int paramInt)
  {
    getWindow().setWindowAnimations(paramInt);
    show();
  }

  public BaseDialog showAnim(BaseAnimatorSet paramBaseAnimatorSet)
  {
    this.showAnim = paramBaseAnimatorSet;
    return this;
  }

  public void superDismiss()
  {
    super.dismiss();
  }

  public BaseDialog widthScale(float paramFloat)
  {
    this.widthScale = paramFloat;
    return this;
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.flyco.dialog.widget.base.BaseDialog
 * JD-Core Version:    0.6.2
 */